package com.hugoo.core.slt;

import com.hugoo.core.Conf;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Lovelock.Chan
 */
public class ReloadConfigSevlet extends HttpServlet {

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            String px = request.getSession().getServletContext().getInitParameter(Conf.RPT_CONFIG);
            if (px == null) {
                out.println("<script>alert('系统web.xml中未找到参数【RPT_CONFIG】的配置项，请按照说明配置报表文件路径！');</script>");
            } else {
                Conf.reload(px);
                out.println("<script>alert('重新加载配置文件成功！');</script>");
            }
        } catch (Exception e) {
            out.println("<script>alert('重新加载配置文件失败！【" + e.getLocalizedMessage() + "】');</script>");
        } finally {
            out.close();
        }
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
